<?php
class Analytic extends AppModel {
	var $name = 'Analytic';
	var $useTable = 'analytics';

	function getToday() {
		$conditions = array(
         'date(created) = curdate()'
         );
         return $this->find('all', array('fields'=>'count(ip_address) as Visitors, sum(pageviews) as totalPageViews','conditions'=>$conditions));
	}
	
	function getTodayVisitors() {
		$conditions = array(
         'date(created) = curdate()'
         );
         return $this->find('all', array('fields'=>'count(ip_address) as Visitors', 'conditions'=>$conditions));
	}
	

	function getYesterday() {
		$conditions = array(
         'date(created) = DATE_ADD(CURDATE(), INTERVAL - 1 DAY)'
         );
         return $this->find('all', array('fields'=>'count(ip_address) as Visitors, sum(pageviews) as totalPageViews','conditions'=>$conditions));
		
	}

	function getThisWeek($start , $end) {
		$conditions = array(
         "date(created) BETWEEN '".$start ."' and '".$end."'"
         );
       return $this->find('all', array('fields'=>'count(ip_address) as Visitors, sum(pageviews) as totalPageViews','conditions'=>$conditions));
	}

	function getThisMonth() {
	$conditions = array(
         'Month(created) = Month(curdate())'
         );
         return $this->find('all', array('fields'=>'count(ip_address) as Visitors, sum(pageviews) as totalPageViews','conditions'=>$conditions));
	}
}